package top.mypath.service;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;

import top.mypath.model.vo.InvoiceCheckVO;
import top.mypath.model.vo.OrderVO;
import top.mypath.model.vo.SettlementVO;

import java.io.File;
import java.util.List;

/**
 * @author LiYalin
 */
public class WriteExcelService {


    /**
     * 写入其他的数据
     * @param orders 订单数据
     * @param filePath 文件保存路径
     * @param fileName 保存的文件名
     */
    public void writeOtherSheetData(List<OrderVO> orders,String filePath,String fileName){
        String allFilePath=filePath+ File.separator+fileName;
        EasyExcel.write(allFilePath, OrderVO.class).sheet(0,"其他").doWrite(orders);
    }

    public void writeSettlementData(List<SettlementVO> settlementVOS,String filePath,String fileName){
        String allFilePath=filePath+ File.separator+fileName;
        EasyExcel.write(allFilePath, SettlementVO.class).sheet(1,"结算").doWrite(settlementVOS);
    }

    public void writeInvoiceCheckData(List<InvoiceCheckVO> invoiceCheckVOS, String filePath, String fileName){
        String allFilePath=filePath+ File.separator+fileName;
        EasyExcel.write(allFilePath, InvoiceCheckVO.class).sheet(2,"发票核对表").doWrite(invoiceCheckVOS);
    }

    public void writeAllData(List<OrderVO> orders,List<SettlementVO> settlementVOS,List<InvoiceCheckVO> invoiceCheckVOS, String filePath, String fileName){
        String allFilePath=filePath+ File.separator+fileName;
        ExcelWriter excelWriter = EasyExcel.write(allFilePath).build();
        WriteSheet writeSheet1 = EasyExcel.writerSheet(0, "其他").head(OrderVO.class).build();
        excelWriter.write(orders, writeSheet1);
        WriteSheet writeSheet2 = EasyExcel.writerSheet(1, "结算").head(SettlementVO.class).build();
        excelWriter.write(settlementVOS, writeSheet2);
        WriteSheet writeSheet3 = EasyExcel.writerSheet(2, "发票核对表").head(InvoiceCheckVO.class).build();
        excelWriter.write(invoiceCheckVOS, writeSheet3);
        excelWriter.finish();
    }

}
